package com.mlink.job;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.base.commons.utils.DateUtils;
import com.base.commons.utils.HttpClientUtils;
import com.base.commons.web.utils.PropertyUtil;
import com.mlink.job.quartz.annoations.Job;
import com.mlink.job.quartz.annoations.JobMethod;
import com.mlink.job.quartz.entity.Holiday;
import com.mlink.job.quartz.service.HolidayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 轮询逾期24小时的邮件
 * Created by Irany  2017/12/14 16:20
 */
@Component
@Job(name = "轮询逾期24小时的邮件",cronExpression = "0/59 * * ? * MON-FRI")
public class SendOverdueEmail {
    @JobMethod
    public void doJob(){
        try {
            String now= DateUtils.toString(new Date(),"MMdd");
            Holiday holiday=service.selectOne(new EntityWrapper<Holiday>().where("value={0}",now));
            if (holiday!=null){
                return;
            }
            push();
            logger.debug("轮询逾期24小时的邮件");
        }catch (Exception e){
            e.printStackTrace();
            logger.error("轮询逾期24小时的邮件失败,msg:{}",e.getMessage());
        }
    }
    private void push() throws Exception{
        HttpClientUtils.get(PropertyUtil.get("job.send.url")+"/notify/workNotifier/WorkReminder?token=cuteoa2017");
    }

    @Autowired
    private HolidayService service;

    private Logger logger= LoggerFactory.getLogger(getClass());
}
